package pdm.traj.part.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import pdm.traj.entity.PartInfo;
import pdm.traj.entity.TrackPoint2;
import pdm.traj.entity.TrajQuery;
import pdm.traj.part.PartPlan;
import pdm.traj.util.TrackPointUtil;

public class PartPlanSidGroup extends PartPlan {
	public static final String TAG = "PartPlanSidGroup";
	private String name;
	
	@Override
	public PartInfo getPartInfoByTP(TrackPoint2 tp) {
		String lacid = tp.getLacid();
		int index = lacid.charAt(lacid.length() - 1) % nodeNum;		
		return getPartInfo(index);
	}

	@Override
	public List<PartInfo> getPartInfoBySid(String sid) {
		String lacid = TrackPointUtil.getLacidFromSid(sid);
		int index = lacid.charAt(lacid.length() - 1) % nodeNum;
		List<PartInfo> result = new ArrayList<PartInfo>();
		result.add(getPartInfo(index));
		return result;
	}

	@Override
	public List<PartInfo> getPartInfoByQuery(TrajQuery query) {
		if (query.getSids() == null) {
			// get all sids
			return getAllPartInfo();
		} else {
			Set<PartInfo> rset = new HashSet<PartInfo>();
			List<PartInfo> result = new ArrayList<PartInfo>();
			for (String sid : query.getSids()) {
				List<PartInfo> pil = getPartInfoBySid(sid);
				rset.addAll(pil);
			}
			result.addAll(rset);
			return result;
		}
	}

	@Override
	protected void initPlan() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
